package day01.com.it;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.function.Consumer;

/*
 *文件名: ArrayListDemo
 *创建者:
 *创建时间:2025/5/19 15:34
 *描述:
 */
public class ArrayListDemo {
    public static void main(String[] args) {
        //定义一个空白的ArrayList对象
        ArrayList<String> list = new ArrayList<String>();
        //增
        list.add("zhangsan");
        //改
        list.add(0, "lisi");
        //查
        String List=list.get(0);
        System.out.println(List);
        //删
        list.remove(0);
        System.out.println(list);
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        System.out.println("<------------遍历1----------->");
        //for 基本
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("<------------遍历2----------->");
        //for 增强
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("<------------遍历3----------->");
        //迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("<------------遍历4----------->");
        Consumer<String> consumer = System.out::println;
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        list.forEach( name -> System.out.println(name));

        list.forEach(System.out::println);





    }
}
